//为了给出精确的提示,我们用工厂方法进行封装个
function catchError(msg: string) {
    return function (target: any, key: string, descriptor: PropertyDescriptor) {
    
      let fn = descriptor.value;

      descriptor.value = () => {
        try {
          fn();
        } catch (e) {
          console.log(msg);
        }
      };
    };
  }
  const BookInfo: any = undefined;
  
  class Book {
    @catchError("BookInfo -- name 不存在")
    getBookName() {
      return BookInfo.name;
    }
    @catchError("BookInfo -- price 不存在")
    getBookPrice() {
      return BookInfo.price;
    }
  }
  
  const book = new Book();
  book.getBookName(); //BookInfo -- name 不存在
  book.getBookPrice(); //BookInfo --- price 不存在